﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StructureMap;
using MedicalCare.DbLayer.Adaptors;
using MedicalCare.EntityDefinitions.Entities;

namespace MedicalCare.Common
{
    public class User
    {
        public static IList<UserEntity> GetUserListByUserRole(string userRoleName)
        {
            var userAdaptor = ObjectFactory.GetInstance<IUserAdaptor>();
            string whereStr = " RoleCode = '" + userRoleName +"'";
            return userAdaptor.GetUsers("Name", "DESC", whereStr);
        }

        public static int GetUserIDByUserName(string userName)
        { 
            var userAdaptor = ObjectFactory.GetInstance<IUserAdaptor>();
            string whereStr = " Name like '%" + userName + "%'";
            IList<UserEntity> singleUser =  userAdaptor.GetUsers("Name", "DESC", whereStr);
            if (singleUser != null && singleUser.Count > 0)
            {
                return singleUser.FirstOrDefault().Id;
            }
            return 0;
        }
    }
}